import { httpClient, ApiResponse } from '../http/client';

export interface LoginRequest {
  username: string;
  password: string;
}

export interface LoginResponse {
  user: {
    id: string;
    username: string;
    email: string;
    role: string;
  };
  token: string;
  refreshToken: string;
}

export interface RefreshTokenRequest {
  refreshToken: string;
}

export class AuthAPI {
  static async login(credentials: LoginRequest): Promise<ApiResponse<LoginResponse>> {
    return httpClient.post<LoginResponse>('/api/auth/login', credentials);
  }

  static async logout(): Promise<ApiResponse<void>> {
    return httpClient.post<void>('/api/auth/logout');
  }

  static async refreshToken(refreshToken: string): Promise<ApiResponse<LoginResponse>> {
    return httpClient.post<LoginResponse>('/api/auth/refresh', { refreshToken });
  }

  static async getProfile(): Promise<ApiResponse<LoginResponse['user']>> {
    return httpClient.get<LoginResponse['user']>('/api/auth/profile');
  }

  static async changePassword(oldPassword: string, newPassword: string): Promise<ApiResponse<void>> {
    return httpClient.post<void>('/api/auth/change-password', {
      oldPassword,
      newPassword
    });
  }
}

export default AuthAPI;